Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a pushd context #206

Closed
wants to merge 1 commit into from
Closed

Add a pushd context #206

wants to merge 1 commit into from

Conversation

ppannuto
Copy link
Contributor

I find that I write this little boilerplate all the time and I think
other sh users would find it useful as well. This simply creates a
context to run commands in another directory and ensures that the
original working directory will be returned to.

Usage:

from sh import pushd, pwd

pwd()
with pushd('/tmp'):
    pwd()
pwd()

I find that I write this little boilerplate all the time and I think
other sh users would find it useful as well. This simply creates a
context to run commands in another directory and ensures that the
original working directory will be returned to.

Usage:

```python
from sh import pushd, pwd

pwd()
with pushd('/tmp'):
    pwd()
pwd()
```
@amoffat
Copy link
Owner

amoffat commented Dec 23, 2014

thanks Pat. merged into release-1.10. i generalized it a bit more so that the with-context can work with any special keyword argument, but i left in the pushd alias because it will probably be used the most:

from sh import args, pwd, pushd

print pwd()
with args(_cwd="/tmp"): # or pushd("/tmp")
    pwd()
print pwd()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants